//
//  VisitorTableViewController.swift
//  微博项目
//
//  Created by 原晓桢 on 15/11/3.
//  Copyright © 2015年 itcast.cn. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {

    /// 访客登陆标记
    private var visitorLogon = false
    
    /// 访客视图
    var visitorView : VisitorView?
    
    override func loadView() {
        
        //判断访客是否登陆
        visitorLogon ? super.loadView() : setupVisitorView()
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
    }
    
    ///MARK - 设置访客视图
    private func setupVisitorView() {
        
        //替换视图
        visitorView = VisitorView()
        view = visitorView
        
        //添加监听游客视图的方法
        visitorView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        //设置导航控制器按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: "visitorViewDidLogin")
    }
}

// MARK: - 监听游客视图方法
extension VisitorTableViewController{
    
    func visitorViewDidRegister(){
        print("注册")
    }
    func visitorViewDidLogin(){
        print("登陆")
        let vi = OAuthViewController()
        let vc = UINavigationController(rootViewController: vi)
        presentViewController(vc, animated: true, completion: nil)
    }
}

